package com.ecourseapp.NativeForRN;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.ecourseapp.R;
import com.juziwl.ijkplayerlib.media.AndroidMediaController;
import com.juziwl.ijkplayerlib.media.IjkVideoView;

/**
 * @author Army
 * @version V_1.0.0
 * @date 2018/8/21
 * @description
 */
public class VideoPlayerWithControllerActivity extends AppCompatActivity {

    private IjkVideoView player;
    private AndroidMediaController mMediaController;

    public static void naveToActivity(Activity activity, String url) {
        Intent intent = new Intent(activity, VideoPlayerWithControllerActivity.class);
        intent.putExtra("url", url);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_player_with_controller);
        player = (IjkVideoView) findViewById(R.id.player);
        mMediaController = new AndroidMediaController(this);
        final View start = findViewById(R.id.start);
        start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                start.setVisibility(View.GONE);
                player.setMediaController(mMediaController);
                String url = getIntent().getStringExtra("url");
                player.setVideoPath(url);
                player.start();
            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        if (player != null) {
            player.stopPlayback();
            player = null;
        }
        super.onDestroy();
    }

    @Override
    public void onBackPressed() {
        finish();
    }
}
